/*
 * =====================================================================================
 *
 *       Filename:  map.cpp
 *
 *    Description:  实现map类
 *
 *        Version:  1.0
 *        Created:  2008年11月05日 22时55分10秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Dr. Fritz Mehner (mn), mehner@fh-swf.de
 *        Company:  FH Südwestfalen, Iserlohn
 *
 * =====================================================================================
 */

#include <iostream>
#include <string.h>

#include "map.h"

//extern const unsigned Map[22][14];
const unsigned Map[_MAP_HIGHT][_MAP_WIDTH] = {
	{1,1,0,0,0,0,0,0,0,0,0,0,1,1}, //0
	{1,1,0,0,0,0,0,0,0,0,0,0,1,1}, //1
	{1,1,0,0,0,0,0,0,0,0,0,0,1,1}, //2
	{1,1,0,0,0,0,0,0,0,0,0,0,1,1}, //3
	{1,1,0,0,0,0,0,0,0,0,0,0,1,1}, //5
	{1,1,0,0,0,0,0,0,0,0,0,0,1,1}, //6
	{1,1,0,0,0,0,0,0,0,0,0,0,1,1}, //7
	{1,1,0,0,0,0,0,0,0,0,0,0,1,1}, //8
	{1,1,0,0,0,0,0,0,0,0,0,0,1,1}, //9
	{1,1,0,0,0,0,0,0,0,0,0,0,1,1}, //10
	{1,1,0,0,0,0,0,0,0,0,0,0,1,1}, //11
	{1,1,0,0,0,0,0,0,0,0,0,0,1,1}, //12
	{1,1,0,0,0,0,0,0,0,0,0,0,1,1}, //13
	{1,1,0,0,0,0,0,0,0,0,0,0,1,1}, //14
	{1,1,0,0,0,0,0,0,0,0,0,0,1,1}, //15
	{1,1,0,0,0,0,0,0,0,0,0,0,1,1}, //16
	{1,1,0,0,0,0,0,0,0,0,0,0,1,1}, //17
	{1,1,0,0,0,0,0,0,0,0,0,0,1,1}, //18
	{1,1,0,0,0,0,0,0,0,0,0,0,1,1}, //19
	{1,1,0,0,0,0,0,0,0,0,0,0,1,1}, //20
	{1,1,1,1,1,1,1,1,1,1,1,1,1,1}, //21
	{1,1,1,1,1,1,1,1,1,1,1,1,1,1} //22
};

my_map::my_map()
{
	m_pMap = (unsigned*)new unsigned[sizeof Map];
}

my_map::~my_map()
{
	if(m_pMap)
		delete[] m_pMap;
	m_pMap = NULL;
}

bool my_map::Init_map()
{
	if(m_pMap)
		return memcpy(m_pMap, &Map[0][0], sizeof Map) ? true: false;
	return false;
}

unsigned* my_map::get_map()
{
	return m_pMap;
}

unsigned my_map::get_map(unsigned _x, unsigned _y)
{
	if(_x < 2 && _x > 11 && _y > 19)
		return _WALL;

	return _MAP(_x,_y) ? _FULL : _EMPTY ;
}

unsigned my_map::set_map(unsigned _x, unsigned _y)
{
	if(_x < 2 && _x > 11 && _y > 19)
		return _WALL;

	*_MAP(_x,_y) = _FULL;
	return _MAP(_x,_y) ? _FULL : _EMPTY;
}

unsigned my_map::clear_map(unsigned _x, unsigned _y)
{
	if(_x < 2 && _x > 11 && _y > 19)
		return _WALL;

	*_MAP(_x,_y) = _EMPTY;
	return _MAP(_x,_y) ? _FULL: _EMPTY ;
}

